<?php
/**
 * Joomla! 1.5 component jhtraq
 *
 * @version $Id: controller.php 2010-03-09 08:28:06 svn $
 * @author JHShop
 * @package Joomla
 * @subpackage jhtraq
 * @license GNU/GPL
 *
 * Traq type system for Joomla
 *
 * This component file was created using the Joomla Component Creator by Not Web Design
 * http://www.notwebdesign.com/joomla_component_creator/
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.controller' );
require_once( JPATH_COMPONENT.DS.'helpers'.DS.'helper.php' );
/**
 * jhtraq Controller
 *
 * @package Joomla
 * @subpackage jhtraq
 */
class JhtraqController extends JController {
    /**
     * Constructor
     * @access private
     * @subpackage jhtraq
     */
    function __construct() {
        //Get View
        if(JRequest::getCmd('view') == '') {
            JRequest::setVar('view', 'default');
        }
        $this->item_type = 'Default';
		
		$this->mergeUser();
        parent::__construct();
        
        JSubMenuHelper::addEntry(JText::_('COM_JHTRAQ_DASHBOARD'), 'index.php?option=com_jhtraq',(JRequest::getVar('view')) == 'default'?true:false);
        JSubMenuHelper::addEntry(JText::_('COM_JHTRAQ_SETTINGS'), 'index.php?option=com_jhtraq&view=settings',(JRequest::getVar('view')) == 'settings'?true:false);
        JSubMenuHelper::addEntry(JText::_('COM_JHTRAQ_PROJECTS'), 'index.php?option=com_jhtraq&view=projects',(JRequest::getVar('view')) == 'projects'?true:false);
        JSubMenuHelper::addEntry(JText::_('COM_JHTRAQ_USERS'), 'index.php?option=com_jhtraq&view=users',(JRequest::getVar('view')) == 'users'?true:false);
        JSubMenuHelper::addEntry(JText::_('COM_JHTRAQ_MILESTONES'), 'index.php?option=com_jhtraq&view=milestones',(JRequest::getVar('milestones')) == 'default'?true:false);
        JSubMenuHelper::addEntry(JText::_('COM_JHTRAQ_VERSIONS'), 'index.php?option=com_jhtraq&view=versions',(JRequest::getVar('versions')) == 'default'?true:false);
        JSubMenuHelper::addEntry(JText::_('COM_JHTRAQ_TICKETS'), 'index.php?option=com_jhtraq&view=tickets',(JRequest::getVar('tickets')) == 'default'?true:false);
        JSubMenuHelper::addEntry(JText::_('COM_JHTRAQ_COMPONENTS'), 'index.php?option=com_jhtraq&view=components',(JRequest::getVar('components')) == 'default'?true:false);
        JSubMenuHelper::addEntry(JText::_('COM_JHTRAQ_RELEASES'), 'index.php?option=com_jhtraq&view=releases',(JRequest::getVar('releases')) == 'default'?true:false);


    }
	
	function mergeUser()
	{
		
		$user =& JFactory::getUser();
		$db =& JFactory::getDBO();
		
		$uid = (int)$user->id;
		$db->setQuery("Select * from #__jhtraq_users where id=$uid");
		$tuser = $db->loadObject();
		if(!$tuser->id)
		{
			$db->setQuery("Insert into #__jhtraq_users(`id`,`group_id`) values('$uid','1')"); //hardcoded - make admins admins
			$db->query();
		}
			
	}
	
}
?>
